package com.zrf.testchatgpt.service.impl;

import com.zrf.testchatgpt.service.RedisService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Set;


@Service
public class RedisServiceImpl implements RedisService {
     @Resource
    private RedisTemplate<Object, Object> redisTemplate;

    @Override
    public void putHash(String hashName, String key, Object value) {
        redisTemplate.opsForHash().put(hashName, key, value);
    }

    @Override
    public Object getHashValueByKey(String hashName, String key) {
        return redisTemplate.opsForHash().get(hashName, key);
    }

    @Override
    public void removeHashKey(String hashName, String key) {
        redisTemplate.opsForHash().delete(hashName, key);
    }

    @Override
    public void removeHash(String hashName) {
        redisTemplate.delete(hashName);
    }

    @Override
    public int sizeHash(String hashName) {
        return redisTemplate.opsForHash().size(hashName).intValue();
    }

    @Override
    public Set<Object> keysHash(String hashName) {
        return redisTemplate.opsForHash().keys(hashName);
    }

    @Override
    public Collection<Object> valuesHash(String hashName) {
        return redisTemplate.opsForHash().values(hashName);
    }
}
